package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.Arrays;

class MinimumDifferenceBetweenHighestAndLowestOfKScores {
    // 2022-08-22 14:08:42
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int minimumDifference(int[] nums, int k) {
            Arrays.sort(nums);
            int ans = nums[k - 1] - nums[0];
            for (int i = k; i < nums.length; i++) {
                ans = Math.min(nums[i] - nums[i - k + 1], ans);
            }
            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}